package accessDao

import (
	"goback/constant"
	"goback/model"
	"gorm.io/gorm"
	"runtime/debug"
)

// GetById 通过id查询访问记录
func GetById(id int64) *model.Access {
	db := constant.Db
	var access model.Access = model.Access{}
	db.First(&access, id)
	return &access
}

// Save 保存一条记录
func Save(access *model.Access) error {
	var err error = nil
	err = constant.Db.Transaction(func(tx *gorm.DB) error {
		println(tx)
		println(constant.Db)
		err = tx.Create(access).Error
		if err != nil {
			println(string(debug.Stack()))
		}
		return err
	})
	return err
}
